package com.example.demo.repo;

import com.example.demo.model.User;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.stereotype.Repository;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.Map;
import java.util.Optional;

@Repository
public class UserRepository {

    @Resource
    PasswordEncoder passwordEncoder;

    public Optional<User> findByUsername(String username){

        Map<String,User> userMap = new HashMap<>();

        userMap.put("admin",new User(1, "admin",passwordEncoder.encode("1234"),"ADMIN"));
        userMap.put("dba",new User(2,"dba",passwordEncoder.encode("123"),"DBA"));
        userMap.put("huanghe",new User(3,"huanghe",passwordEncoder.encode("123"),"USER"));

        return Optional.ofNullable(userMap.get(username));


    }
}
